/*
 * Copyright 2017 Matthew Tamlin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.matthewtamlin.fortytwo.example;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        getWindow().setStatusBarColor(Color.BLACK.getValue());
        getWindow().setStatusBarVisibility(Component.HIDE);
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_btn_single).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                showSingleSelectionActivity();
            }
        });
        findComponentById(ResourceTable.Id_btn_multiple).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                showMultipleSelectionActivity();
            }
        });
    }

    /**
     * On click listener method for launching the single selection activity.
     *
     */
    public void showSingleSelectionActivity() {
        Intent intent = new Intent();

        // 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
        Operation operation = new Intent.OperationBuilder()
            .withBundleName(getBundleName())
            .withAbilityName(SingleSelectionAbility.class)
            .build();

        // 把operation设置到intent中
        intent.setOperation(operation);
        startAbility(intent);
    }

    /**
     * On click listener method for launching the multiple selection activity.
     *
     */
    public void showMultipleSelectionActivity() {
        Intent intent = new Intent();

        // 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
        Operation operation = new Intent.OperationBuilder()
            .withBundleName(getBundleName())
            .withAbilityName(MultipleSelectionAbility.class)
            .build();

        // 把operation设置到intent中
        intent.setOperation(operation);
        startAbility(intent);
    }
}
